package design.donkey.auto.ddl.dialect.mysql.handler;

import design.donkey.auto.ddl.model.ColumnMetaModel;

/**
 * 是否允许为空
 *
 * @since 0.0.1
 * @author zhangjiakung
 */
public class ColumnHandlerNullable implements ColumnHandler {
    @Override
    public String handle(ColumnMetaModel columnMetaModel) {
        // 主键默认不允许为 NULL
        if (columnMetaModel.isPrimaryKey()) {
            return "NOT NULL";
        }
        // 非主键使用用户注解配置
        return columnMetaModel.isNullable() ? null : "NOT NULL";
    }
}
